import eventBus from "@/eventBus";

export default function (refValue) {
	return {
		mounted() {
			this.$refs[refValue].addEventListener("scroll", this.handleScroll);
			eventBus.$on("setScrollTop", this.handleScrollTop);
		},
		methods: {
			handleScroll() {
				eventBus.$emit("mainScroll", this.$refs[refValue]);
			},
			handleScrollTop(top) {
				this.$refs[refValue].scrollTop = top;
			},
		},
		beforeDestroy() {
			eventBus.$emit("mainScroll");
			eventBus.$off("setScrollTop", this.setScrollTop);
			this.$refs[refValue].removeEventListener("scroll", this.handleScroll);
		},
	};
}
